using MediatR;
using B.S.XZYData.ErrorCode;

namespace B.S.XZYData.Api.Wrter.Application.Command.AssemblyWorkOrder
{
    /// <summary>
    /// 打印装配工单命令
    /// </summary>
    public class PrintAssemblyWorkOrderCommand : IRequest<ApiResult<PrintAssemblyWorkOrderResponseDto>>
    {
        /// <summary>
        /// 装配工单ID
        /// </summary>
        public long Id { get; set; }
    }

    /// <summary>
    /// 打印装配工单响应DTO
    /// </summary>
    public class PrintAssemblyWorkOrderResponseDto
    {
        /// <summary>
        /// 装配工单基本信息
        /// </summary>
        public AssemblyWorkOrderPrintInfoDto WorkOrder { get; set; } = new AssemblyWorkOrderPrintInfoDto();

        /// <summary>
        /// 产品明细列表
        /// </summary>
        public List<ProductDetailPrintInfoDto> ProductDetails { get; set; } = new List<ProductDetailPrintInfoDto>();

        /// <summary>
        /// 二维码内容（单据编号）
        /// </summary>
        public string QrCodeContent => WorkOrder?.DocumentNumber ?? string.Empty;
    }

    /// <summary>
    /// 装配工单打印信息DTO
    /// </summary>
    public class AssemblyWorkOrderPrintInfoDto
    {
        /// <summary>
        /// 主键ID
        /// </summary>
        public long Id { get; set; }

        /// <summary>
        /// 单据编号
        /// </summary>
        public string DocumentNumber { get; set; } = string.Empty;

        /// <summary>
        /// 工单数
        /// </summary>
        public int? WorkOrderCount { get; set; }

        /// <summary>
        /// 已结束工单数
        /// </summary>
        public int? CompletedWorkOrderCount { get; set; }

        /// <summary>
        /// 单据进度(%)
        /// </summary>
        public decimal? DocumentProgress { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        public string? Remarks { get; set; }

        /// <summary>
        /// 创建人
        /// </summary>
        public string? Creator { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime? CreatorDate { get; set; }

        /// <summary>
        /// 修改人
        /// </summary>
        public string? Updator { get; set; }

        /// <summary>
        /// 修改时间
        /// </summary>
        public DateTime? UpdatorDate { get; set; }

        /// <summary>
        /// 制单人（用于打印显示）
        /// </summary>
        public string CreatorDisplay => Creator ?? "未知";

        /// <summary>
        /// 创建时间（用于打印显示）
        /// </summary>
        public string CreatorDateDisplay => CreatorDate?.ToString("yyyy-MM-dd HH:mm:ss") ?? "未知";
    }

    /// <summary>
    /// 产品明细打印信息DTO
    /// </summary>
    public class ProductDetailPrintInfoDto
    {
        /// <summary>
        /// 主键ID
        /// </summary>
        public long Id { get; set; }

        /// <summary>
        /// 层级编号
        /// </summary>
        public string HierarchyNumber { get; set; } = string.Empty;

        /// <summary>
        /// 产品编号
        /// </summary>
        public string ProductNumber { get; set; } = string.Empty;

        /// <summary>
        /// 产品名称
        /// </summary>
        public string ProductName { get; set; } = string.Empty;

        /// <summary>
        /// 产品规格
        /// </summary>
        public string? ProductSpecification { get; set; }

        /// <summary>
        /// 工单编号
        /// </summary>
        public string? WorkOrderDetailNumber { get; set; }

        /// <summary>
        /// 数量
        /// </summary>
        public int Quantity { get; set; }

        /// <summary>
        /// 完成数
        /// </summary>
        public int? CompletedQuantity { get; set; }

        /// <summary>
        /// 产品规格显示（用于打印）
        /// </summary>
        public string ProductSpecificationDisplay => ProductSpecification ?? "-";

        /// <summary>
        /// 数量显示（用于打印）
        /// </summary>
        public string QuantityDisplay => Quantity.ToString();

        /// <summary>
        /// 完成数显示（用于打印）
        /// </summary>
        public string CompletedQuantityDisplay => (CompletedQuantity ?? 0).ToString();
    }
} 